'use strict';
const db = uniCloud.database()
const coll = db.collection('list')
const coll1 = db.collection('userinfo')
const dbCmd = db.command
exports.main = async (event, context) => {
	let res = await coll.add(event)
	console.log(res)
	//奖励
	if (event.leixing == 1) {
		let res1 = await coll1.where({
			_id: event.userid
		}).update({
			total: dbCmd.inc(event.money)
		})
		console.log(res1)
		return res1
	} else {
		//惩罚
		let res2 = await coll1.where({
			_id: event.userid
		}).update({
			total: dbCmd.inc(0 - event.money)
		})
		return res2
	}
};
